package
{
	import flash.display.DisplayObject;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.KeyboardEvent;
	import flash.geom.Point;
	import flash.ui.Keyboard;
	import flash.utils.Dictionary;
	
	public class Tile
	{
		private var _type:int;
		private var _direction:int;
		private var _tileArr:Array;
		private var _tempShape:Shape;
		private var _tempX:int;
		private var _tempY:int;
		private var _smallTempX:int;
		private var _smallTempY:int;
		private var _hitValue:Boolean;
		private var _nextTileArr:Array;
		private var _nextDirection:int;
		
		
		public function Tile()
		{
			super();
		}
		
		private function init():void
		{

		}
		
		public function set type($type:int):void
		{
			_type = $type;
		}
		
		public function get type():int
		{
			return _type;
		}
		
		public function set direction($direction:int):void
		{
			_direction = $direction;
		}
		
		public function get direction():int
		{
			return _direction;
		}
		
		public function get tempX():int
		{
			return _tempX;
		}
		
		public function set tempX($tempX:int):void
		{
			_tempX = $tempX;
		}
		
		public function get tempY():int
		{
			return _tempY;
		}
		
		public function set tempY($tempY:int):void
		{
			_tempY = $tempY;
		}
		
//		public function checkFloor():Boolean
//		{
//			for(var i:int; i < _tileArr.length; i ++)
//			{
//				_smallTempX = _tileArr[i][0] + _tempX;
//				_smallTempY = _tileArr[i][1] + _tempY;
//				if(TileUtils.checkHitFloor(_smallTempX,_smallTempY,0,1))
//				{
//					return false;
//				}
//			}
//			return true;
//		}
		
		public function checkTransform():Boolean
		{
			_nextDirection = _direction+1>3 ? 0 : _direction+1;
			_nextTileArr = TileUtils.computeTileData(_type, _nextDirection);
			for(var i:int; i < _nextTileArr.length; i ++)
			{
				
				_smallTempX = _nextTileArr[i][0] + _tempX;
				_smallTempY = _nextTileArr[i][1] + _tempY;
				if(TileUtils.checkHitBorder(_smallTempX,_smallTempY,0,0) || TileUtils.checkHitTile(_smallTempX,_smallTempY,0,0))
				{
					return false;
				}
			}
			return true;
			return true;
		}
		
		public function checkDown():Boolean
		{
			for(var i:int; i < _tileArr.length; i ++)
			{
				_smallTempX = _tileArr[i][0] + _tempX;
				_smallTempY = _tileArr[i][1] + _tempY;
				if(TileUtils.checkHitBorder(_smallTempX,_smallTempY,0,1) || TileUtils.checkHitTile(_smallTempX,_smallTempY,0,1))
				{
					return false;
				}
			}
			return true;
		}
		
		public function checkLeft():Boolean
		{
			for(var i:int; i < _tileArr.length; i ++)
			{
				_smallTempX = _tileArr[i][0] + _tempX;
				_smallTempY = _tileArr[i][1] + _tempY;
				if(TileUtils.checkHitBorder(_smallTempX,_smallTempY,-1,0) || TileUtils.checkHitTile(_smallTempX,_smallTempY,-1,0))
				{
					return false
				}
			}
			return true;
		}
		
		public function checkRight():Boolean
		{
			for(var i:int; i < _tileArr.length; i ++)
			{
				_smallTempX = _tileArr[i][0] + _tempX;
				_smallTempY = _tileArr[i][1] + _tempY;
				if(TileUtils.checkHitBorder(_smallTempX,_smallTempY,1,0) || TileUtils.checkHitTile(_smallTempX,_smallTempY,1,0))
				{
					return false;
				}
			}
			return true;
		}
		
		public function set tileArr($tileArr:Array):void
		{
			_tileArr = $tileArr;
		}
		
		public function get tileArr():Array
		{
			return _tileArr;
		}
		
		public function dispose():void
		{
			_tileArr = null;
		}
	}
}